import { defineStore } from 'pinia'
import request from '@/utils/request'
import { ApiRes } from '@/types/data'
import { TopCategory, SubCategory } from '@/types/category'

/**
 * 参数1：仓库的名字
 * 参数2：仓库的配置
 */
export default defineStore('category', {
  state: () => {
    return {
      // 分类列表
      topCategory: {} as TopCategory, // 一级分类
      subCategory: {} as SubCategory
    }
  },
  actions: {
    async getTopCategory(id: string) {
      const res = await request.get<ApiRes<TopCategory>>(`/category?id=${id}`)
      // console.log(res);
      this.topCategory = res.data.result
    },

    async getSubCategory(id: string) {
      const res = await request.get<ApiRes<SubCategory>>(`/category/sub/filter?id=${id}`)
      // console.log(res);
      this.subCategory = res.data.result

    },
  }
})
